package dataBase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RetrieveDBData {
	private static PreparedStatement statement;
	//We are aware of the code repetition but we need separate methods for all of these.
	// Get Barbarians Count
	public static int getBarbariansFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT barbarians FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("barbarians");
		}
		return 0;
	}

	// Get Barbarian AD Level
	public static int getBarbarianADLevelFromCurrentLoggedInUser(
			Connection dbCon, String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT barbarianADLevel FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("barbarianADLevel");
		}
		return 0;
	}

	// Get Barbarian HP Level
	public static int getBarbarianHPLevelFromCurrentLoggedInUser(
			Connection dbCon, String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT barbarianHPLevel FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("barbarianHPLevel");
		}
		return 0;
	}

	// Get Archers Count
	public static int getArchersFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT archers FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("archers");
		}
		return 0;
	}

	// Get Archer AD Level
	public static int getArcherADLevelFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT archerADLevel FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("archerADLevel");
		}
		return 0;
	}

	// Get Archer HP Level
	public static int getArcherHPLEvelFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT archerHPLEvel FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("archerHPLEvel");
		}
		return 0;
	}

	// Get Wizards Count
	public static int getWizzardsFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT wizzards FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("wizzards");
		}
		return 0;
	}

	// Get Wizard AD Level
	public static int getWizzardADLevelFromCurrentLoggedInUser(
			Connection dbCon, String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT wizzardADLevel FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("wizzardADLevel");
		}
		return 0;
	}

	// Get Wizard HP Level
	public static int getWizzardHPLevelFromCurrentLoggedInUser(
			Connection dbCon, String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT wizzardHPLevel FROM hp_ad_levels WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("wizzardHPLevel");
		}
		return 0;
	}

	// Get Current Gold
	public static int getGoldFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT gold FROM users WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("gold");
		}
		return 0;
	}

	// Get Current Food
	public static int getFoodFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT food FROM users WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("food");
		}
		return 0;
	}

	// Get Army Capacity
	public static int getArmy_capacityFromCurrentLoggedInUser(Connection dbCon,
			String username) throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT army_capacity FROM users WHERE username LIKE "
						+ "'" + username + "'");
		ResultSet result = statement.executeQuery();
		while (result.next()) {
			return result.getInt("army_capacity");
		}
		return 0;
	}
}
